from odoo import fields, models, api
from odoo.exceptions import UserError


class RPItem(models.Model):
    _name = 'rp.item'
    _description = '物品'

    def _default_get_kg(self):
        kg = self.env['uom.uom'].search([('name', '=', 'kg')])
        return kg.id if kg else False

    def _default_get_units(self):
        units = self.env['uom.uom'].search([('name', '=', 'Units')])
        return units.id if units else False

    rp_parcel_id = fields.Many2one(string='从属包裹', comodel_name='rp.parcel', ondelete='cascade')

    name = fields.Char(string='物品名称', required=True, index=True, copy=False)

    """
    车辆零配件及配件 , Vehicle parts and accessories      , repuestos y accesorios de vehiculos
    音乐物品       , Articles of music                  , articulos de musica
    家居、家具和diy , Home, furniture and diy            , hogar,muebles y bricolaje
    玩具及游戏      , Toys and games                     , juguetes y juegos
    洋娃娃和毛绒玩具 , Dolls and stuffed animals          , munecas y peluches
    电子游戏和游戏机 , Video games and consoles           , videojuegos y consolas
    巧克力和糖果    , Chocolate and candy                 , chocolate y golosinas
    健康与美容      , Health and beauty                  , salud y belleza
    书籍、漫画和杂志 , Books, comics and magazines        , libros , comics y revistas
    服装、鞋类及配件 , Clothing, footwear and accessories  , ropa , calzado y  accesorios
    体育           , Sports articles                    , articulos deportivos
    考古收藏家的物品 , Items of archaeological collector   , articulos de coleccionista arqueologicos
    钱币收藏家的物品 , Collector's articles               , articulos de coleccionista numismaticos
    其他           , other                              , otros
    """

    type = fields.Selection(string='物品类型', selection=[('vehicle', '车辆零配件及配件'),
                                                      ('articles', '音乐物品'),
                                                      ('furniture', '家具物品'),
                                                      ('toys', '玩具'),
                                                      ('dolls', '洋娃娃、毛绒玩具'),
                                                      ('consoles', '电子游戏、游戏机'),
                                                      ('candy', '巧克力、糖果'),
                                                      ('health', '健康、美容'),
                                                      ('books', '书籍'),
                                                      ('clothing', '服饰'),
                                                      ('sports', '体育物品'),
                                                      ('archaeology', '考古收藏'),
                                                      ('coin', '钱币收藏'),
                                                      ('other', '其他')], required=True)

    product_country_id = fields.Many2one(string='生产国家', comodel_name='res.country', required=True)
    quantity = fields.Integer(string='数量')
    quantity_uom_id = fields.Many2one(string='数量单位', comodel_name='uom.uom', domain=[('category_id', '=', 1)], default=_default_get_units)
    value = fields.Float(string='单个价值', digits=(8, 3))

    weight = fields.Float(string='单个重量', digits=(8, 3))
    weight_uom_id = fields.Many2one(string='重量单位', comodel_name='uom.uom', domain=[('category_id', '=', 2)], default=_default_get_kg)

    hs_code = fields.Char(string='海关编码')
    desc = fields.Text(string='描述')
